package com.guigu.dh.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.guigu.dh.common.result.Result;
import com.guigu.dh.pojo.user.UserInfo;
import com.guigu.dh.service.UserInfoService;
import com.guigu.dh.vo.user.UserInfoQueryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/user")
public class UserInfoController {

    @Autowired
    private UserInfoService userInfoService;

    @PostMapping("/list/{currentPage}/{limit}")
    public Result getUserListPage(@PathVariable Integer currentPage,
                                  @PathVariable Integer limit,
                                  @RequestBody UserInfoQueryVo userInfoQueryVo){
        // 创建分页的对象
        IPage<UserInfo> iPage = new Page<>(currentPage,limit);
        // 调用分页的方法
        iPage = userInfoService.findAllPage(iPage,userInfoQueryVo);

        // 返回结果对象
        return Result.ok(iPage);
    }

    // 修改用户锁定状态
    @PutMapping("/lock/{id}/{status}")
    public Result lock(@PathVariable Long id,
                       @PathVariable Integer status) {
        Boolean result = userInfoService.lockStatus(id,status);
        if (result) {
            return Result.ok();
        }
        return Result.fail();
    }


}
